package com.ruoyi.game.websocket.handler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.WebSocketExtension;
import org.springframework.web.socket.WebSocketMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.security.Principal;
import java.util.*;

@Slf4j
public class MockRobotSession implements WebSocketSession {

    private final String id = UUID.randomUUID().toString();
    private final Map<String, Object> attributes = new HashMap<>();
    private final Long playerId;

    public MockRobotSession(Long playerId) {
        this.playerId = playerId;
        attributes.put("playerId", playerId);
    }

    @Override
    public String getId() {
        return id;
    }

    @Override
    public Map<String, Object> getAttributes() {
        return attributes;
    }

    // 以下方法可根据需要实现或返回空，供广播使用即可
    @Override public URI getUri() { return null; }

    @Override
    public HttpHeaders getHandshakeHeaders() {
        return null;
    }

    @Override public Principal getPrincipal() { return null; }
    @Override public InetSocketAddress getLocalAddress() { return null; }
    @Override public InetSocketAddress getRemoteAddress() { return null; }
    @Override public String getAcceptedProtocol() { return null; }
    @Override public void setTextMessageSizeLimit(int messageSizeLimit) {}
    @Override public int getTextMessageSizeLimit() { return 0; }
    @Override public void setBinaryMessageSizeLimit(int messageSizeLimit) {}
    @Override public int getBinaryMessageSizeLimit() { return 0; }
    @Override public List<WebSocketExtension> getExtensions() { return Collections.emptyList(); }
    public void sendMessage(WebSocketMessage<?> message) throws IOException {
        // 打印消息内容和目标玩家ID
        log.info("[MockRobotSession] 发送消息给机器人 playerId={} : {}", playerId, message.getPayload());
    }
    @Override public boolean isOpen() { return true; }
    @Override public void close() throws IOException {}
    @Override public void close(CloseStatus status) throws IOException {}
}
